package com.acce.gxsc.page.registerCar.addBoxInfo;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;

import com.acce.gxsc.R;
import com.acce.gxsc.common.App;
import com.acce.gxsc.common.Tools;
import com.acce.sdk.base.mvp.BaseMvpActivity;
import com.acce.sdk.utils.StringUtils;
import com.acce.sdk.widget.EditWithTitle;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by huxley on 2017/5/26.
 */

public class AddBoxInfoActivity extends BaseMvpActivity<AddBoxInfoView, AddBoxInfoPresenter> implements AddBoxInfoView {


    @Bind(R.id.ewt_box_no)
    EditWithTitle mEwtBoxNo;
    @Bind(R.id.ewt_box_size)
    EditWithTitle mEwtBoxSize;

    @Override
    protected AddBoxInfoPresenter createPresenter() {
        return new AddBoxInfoPresenter();
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_box_info);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        Intent intent = getIntent();
        if (intent == null) {
            return;
        }
        if (intent.hasExtra("preContainNo")) {
            mEwtBoxNo.setContent(intent.getStringExtra("preContainNo"));
        }
        ArrayList<String> boxSizeList = new ArrayList<>();
        if(!App.isDongGuanShiChang) {
            boxSizeList.add("40尺柜");
            boxSizeList.add("45尺柜");
            boxSizeList.add("30尺柜");
            boxSizeList.add("20尺柜");
        }else {
            boxSizeList.add("五十铃");
            boxSizeList.add("6.8米");
            boxSizeList.add("9.6米");
            boxSizeList.add("冷柜");
            boxSizeList.add("平板车");
        }
        mEwtBoxSize.setSpinnerData(boxSizeList);
    }

    @OnClick(R.id.btn_save)
    public void onClick() {
        String boxNo = mEwtBoxNo.getContent();
        String boxSize = mEwtBoxSize.getContent();
        mPresenter.getTime(boxNo);

//        if (!StringUtils.areNotEmpty(boxNo)) {
//            ToastUtils.show("请填写柜号！");
//            return;
//        }
    }


    @Override
    public void getTimeSuccess(String time) {
        String message;
        if (StringUtils.isEmpty(time)) {
            message = "该车辆第一次来到本市场";
        } else {
            message = "该车辆已在 " + Tools.getStayTime(time) + " 前录入";
        }
        final AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
        final AlertDialog alertDialog1 = builder1
                .setTitle("提示")
                .setMessage(message)
                .setNegativeButton("取消", null)
                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        String boxNo = mEwtBoxNo.getContent();
                        String boxSize = mEwtBoxSize.getContent();
                        Intent intent = new Intent();
                        intent.putExtra("preContainNo", boxNo);
                        intent.putExtra("preContainSize", boxSize);
                        setResult(RESULT_OK, intent);
                        finish();
                    }
                }).create();
        alertDialog1.setCanceledOnTouchOutside(false);
        alertDialog1.show();
    }
}
